package com.harmontronics.hanma.paas.paas.domain.iam.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.persistence.HmBaseModuleRepository;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.HmBaseModule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.common.PageBase;

import com.harmontronics.hanma.paas.paas.domain.iam.repository.mapper.HmBaseModuleMapper;
import com.harmontronics.hanma.paas.paas.domain.iam.repository.po.HmBaseModulePO;
import java.util.List;

@Service("hmBaseModuleService")
@DS("#header.App-Unique")
public class HmBaseModuleService {

    @Autowired
    private HmBaseModuleRepository hmBaseModuleRepository;


    public HmBaseModule findById( Long id) {
            HmBaseModulePO po = hmBaseModuleRepository.getById(id);
        return BeanUtil.toBean(po,HmBaseModule. class);
    }

    public void save(HmBaseModule hmBaseModule) {
            HmBaseModulePO po = BeanUtil.toBean(hmBaseModule,HmBaseModulePO.class);
            hmBaseModuleRepository.save(po);
    }

    public void update(HmBaseModule hmBaseModule) {
            HmBaseModulePO po = BeanUtil.toBean(hmBaseModule,HmBaseModulePO.class);
            hmBaseModuleRepository.updateById(po);
    }

    public void remove(List<Long> ids) {
            hmBaseModuleRepository.removeByIds(ids);
    }

    public List<HmBaseModule> getList() {
        List<HmBaseModulePO> pos = hmBaseModuleRepository.list();
        return Convert.toList(HmBaseModule. class,pos);
    }

    public PageBase<HmBaseModule> getList(int pageNo, int pageSize) {
        Page<HmBaseModulePO> page = new Page<>(pageNo, pageSize);
        IPage<HmBaseModulePO> resultPage =
                    hmBaseModuleRepository.selectPage(Wrappers.emptyWrapper(), page);
        return PageBase.from(resultPage,HmBaseModule. class);
    }

}